from django.http import JsonResponse


class Response:
    def __init__(self, uuid=''):
        self.output = {
            'status': '',
            'msg': ''
        }
        if len(uuid) > 0: self.output['uuid'] = uuid

    def error(self, exception: str, msg=''):
        """根据提供错误信息响应"""
        self.output['status'] = 'error'
        self.output['error_type'] = exception
        self.output['msg'] = msg
        return JsonResponse(self.output, status=500)

    def exception(self, exception: object, msg='') -> JsonResponse:
        """根据异常响应"""
        self.output['status'] = 'error'
        self.output['exception'] = exception.__str__()
        self.output['repr'] = repr(exception)
        self.output['msg'] = msg
        return JsonResponse(self.output, status=500)

    def ok(self, msg='') -> JsonResponse:
        self.output['status'] = 'ok'
        self.output['msg'] = msg
        return JsonResponse(self.output)
